package com.xunbao.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * ClassName:DateUtils
 * Description:
 * Author:yijiawei
 * Date: 2016/5/4 9:27
 */
public class DateUtils {

    public static SimpleDateFormat SDF_YYYYMMDDHHMMSS = new SimpleDateFormat("yyyyMMddHHmmss");

    /**
     * 获取当前日期 格式：yyyyMMddHHmmss
     */
    public static String getNowDateStr() {
        Date date = new Date();
        return SDF_YYYYMMDDHHMMSS.format(date);
    }

    /**
     * 获取d前day天的日期
     */
    public static Date getDateBefore(Date d, int day) {
        Calendar now = Calendar.getInstance();
        now.setTime(d);
        now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
        return now.getTime();
    }

    /**
     * 获取几分钟前的时间
     */
    public static Date getMinuteBefore(Date d, int minute) {
        Calendar now = Calendar.getInstance();
        now.setTime(d);
        now.add(Calendar.MINUTE, -minute);
        return now.getTime();
    }

    /**
     * 获取当前整点时间
     */
    public static Date getTodayOriginDate() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
//        cal.add(Calendar.DAY_OF_MONTH, 1); //当前时间加1天
        return cal.getTime();
    }
}
